/*
* Copyright @2009-2012 www.happyelements.com, all rights reserved.
* Create date: 2012-7-30
* Piggy Dong
* 董文弈
* wenyi.dong@happyelements.com
*/
package
{
	import com.happyelements.components.AssetsList;
	import com.happyelements.components.MapScene;
	import com.happyelements.data.DataModel;
	import com.happyelements.data.DataSerializer;
	import com.happyelements.isolib.IsoWorld;

	import flash.display.Sprite;
	import flash.display.StageScaleMode;

	/**
	 * @author dongpiggyi
	 */
	public class Main extends Sprite
	{
		private var _currentDataModel:DataModel;
		
		private var _mapScene:MapScene;
		
		private var _mapStateContext:MapSceneContext;
		
		public function Main()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			init();
		}
		
		private function init():void
		{
			initScene();
			
			initList();
			
			initStateContext();
		}

		private function initStateContext():void
		{
			_mapStateContext = new MapSceneContext();
			
			_mapStateContext.setup(_mapScene);
		}
		
		private function initScene():void
		{
			_mapScene = new MapScene();
			
			addChild(_mapScene);
		}

		private function initList():void
		{
			var assetsList:AssetsList = new AssetsList(listClickHandler, generateConfigHandler);
			addChild(assetsList);
		}
		
		private function listClickHandler(item:DataModel):void
		{
			_currentDataModel = item;
			
			_mapStateContext.currentState = _mapStateContext.addingTileState;
			_mapStateContext.addingDataModel = item;
			
		}
		
		private function generateConfigHandler():void
		{
			var configMessage:String = DataSerializer.instance.calculateResult(IsoWorld.instance.tileObjectWarehouse);
			trace("------------------ Config XML -------------------");
			trace(configMessage);
			trace("------------------ EOF -------------------");
		}
	}
}
